var _regions=new Array() 
_regions[0]="ef_region_inqu";
_regions[1]="ef_region_result";
_regions[2]="ef_region_mainadd";
_regions[3]="ef_region_solveadd";
_regions[4]="ef_region_feedbackreport";
_regions[5]="ef_region_report";
var fdYxId;
efform_onload = function ()
{  
//	InitRegionShow(); 
	hideAllRegions(_regions);
	$('#ef_region_inqu').show();
	$('#ef_region_result').show();
	$('#ef_region_mainadd').show();
	$('#ef_region_feedbackreport').hide();
	$('#ef_region_solveadd').hide();
// 	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCC11","query"); 
//	var _info = new EiInfo();
//	EiCommunicator.send("ZMCC13", "query", _info, ajax_select_callback);  
//	EiCommunicator.send("ZMCC14", "query", _info, ajax_select_callback1); 	
//	var grid = efgrid.getGridObject("ef_grid_result"); 
//	var selectedRow=grid.getRowData(row_index);
//	if(selectedRow>0){
		var info = new EiInfo();
		EiCommunicator.send("ZMCK11", "query", info, ajax_callback1);
//	}else{
//		$('#ef_region_feedbackreport').hide(); 	
//	}
		

		
	
//	var info = new EiInfo();
//	EiCommunicator.send("ZMCK11", "query", info, ajax_callback1);
}; 
var ajax_callback1 = {
	onSuccess : function(eiInfo) {
		efwindow.hide(); 
		var grid = efgrid.getGridObject("ef_grid_feedbackreport");
		grid.refresh(eiInfo);
	},
	onFail : function(eMsg) {}
};
function InitRegionShow()
{
	hideAllRegions(_regions); 
	$('#ef_region_inqu').show(); 
	$('#ef_region_result').show(); 
	$('#ef_region_mainadd').show(); 
	$('#ef_region_feedbackreport').show(); 
}

/*根据主表查询明细*/
efgrid_onRowClicked = function( grid_id, row_index ){ 
	if(grid_id == "ef_grid_result"){ 
		var grid = efgrid.getGridObject(grid_id); 
		var selectedRow=grid.getRowData(row_index);
		fdYxId=grid.getCellValueByColumnName(row_index,"fdKeyId");
		for(var item in selectedRow){
			var colname=item;
			var colvalue=selectedRow[item];
			$('#ef_region_mainadd').find('#result_add-0-'+colname).val(colvalue);
			//$('#ef_region_solveadd').find('#solve_add-0-'+colname).val(colvalue);
		}	
		var info = new EiInfo();
		info.set("fdYxId",fdYxId); 
		InitRegionShow(); 
		EiCommunicator.send("ZMCK11", "query", info, ajax_callback1);  
	}
}


var ajax_callback = {
		onSuccess : function(eiInfo) {
			var grid = efgrid.getGridObject("ef_grid_result");
			grid.refresh(eiInfo);
			clearAfterSolve("ef_region_mainadd");
		}, 
		onFail:function(eMsg)
		{
			alert("确认失败，原因："+eMsg);
		}

}	

button_insert_onclick = function (){
	var ei_info=new EiInfo();
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('result_add').getRows(0)[0][2]==""){
		EFAlert("汇报时间不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][3]==""){
		EFAlert("汇报人不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][4]==""){
		EFAlert("开始时间不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][5]==""){
		EFAlert("结束时间不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][6]==""){
		EFAlert("演习名称不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][8]==""){
		EFAlert("演习部门不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][9]==""){
		EFAlert("演习内容不能为空");
		return;
	}
	var info = getDetail("ef_region_mainadd","result_add");
	if (null != info) {
		EiCommunicator.send("ZMCK10", "insert", info, ajax_callback);
	}
}

button_update_onclick = function (){
	var ei_info=new EiInfo();
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('result_add').getRows(0)[0][2]==""){
		EFAlert("汇报时间不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][3]==""){
		EFAlert("汇报人不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][4]==""){
		EFAlert("开始时间不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][5]==""){
		EFAlert("结束时间不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][6]==""){
		EFAlert("演习名称不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][8]==""){
		EFAlert("演习部门不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][9]==""){
		EFAlert("演习内容不能为空");
		return;
	}
	var status=$('#result_add-0-fdStatus').val();
	
	var info = getDetail("ef_region_mainadd","result_add");
	if (null != info && status == "草拟") {
		EiCommunicator.send("ZMCK10", "update", info, ajax_callback);
	}else{
		EFAlert("只能对草拟的记录进行修改！"); return;
	} 
}


button_query_onclick = function (){
	efgrid.submitInqu( "ef_grid_result", "ZM","ZMCK10","query");
}

button_delete_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行删除！"); return;
		}
	}
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCK10","delete",true);
	}); 
}
button_report_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行上报！"); return;
		}
	}
	EFConfirm('你确认要上报吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCK10","report",true);
	}); 

}

/*************************************************************************
*************************************************************************
	演习情况信息 方法
*************************************************************************
*************************************************************************/
button_close_onclick = function ()//CLOSE 关闭 
{
 	
	var grid=isSelectedOne("ef_grid_result");
	if (grid == 0)return; 
	var selectedRow=grid.getSelectRowsData()[0]; 

	for(var item in selectedRow){
		var colname=item;
		var colvalue=selectedRow[item];
		$('#solve_add-0-'+colname).val(colvalue); 
		$('#result_add-0-'+colname).val(colvalue); 
		var status=$('#result_add-0-fdStatus').val();
	} 

	if(status != "关闭"){
	 hideAllRegions(_regions);
		$('#ef_region_solveadd').show();
	}
	else{
		EFAlert("已关闭！"); 
		return;
	}
} 

button_solveconfirm_onclick = function ()//CLOSE 主表 确定
{
//	if(efvalidateDiv("ef_region_solveadd")){
		var info = getDetail("ef_region_solveadd","solve_add");
		if (null != info) {
			EiCommunicator.send("ZMCK10", "close", info, ajax_solveconfirm_callback);
		} 
//	}
	InitRegionShow();
} 
var ajax_solveconfirm_callback= {
	onSuccess: function(eiInfo) {
		var grid = efgrid.getGridObject("ef_grid_result");
		grid.refresh(eiInfo);//刷新主表grid
	},
	onFail:function(eMsg)
	{
		alert("确认失败，原因："+eMsg); 
	}
}

button_solvecancel_onclick = function ()//CLOSE 主表 返回
{
	InitRegionShow();
} 



/*************************************************************************
*************************************************************************
	演习情况反馈 方法
*************************************************************************
*************************************************************************/
button_feedback_onclick = function ()//FEEDBACK 反馈 
{
 	
	var grid=isSelectedOne("ef_grid_feedbackreport");
	if (grid == 0)return; 
	var selectedRow=grid.getSelectRowsData()[0]; 

	for(var item in selectedRow){
		var colname=item;
		var colvalue=selectedRow[item];
		$('#report-0-'+colname).val(colvalue); 
	} 

	 hideAllRegions(_regions);
		$('#ef_region_report').show();
	
} 

button_reportconfirm_onclick = function ()//FEEDBACK  确定
{
//	if(efvalidateDiv("ef_region_solveadd")){
		var info = getDetail("ef_region_report","report");
		info.set("fdYxId",fdYxId); 
		if (null != info) {
			EiCommunicator.send("ZMCK11", "insert", info, ajax_reportconfirm_callback);
		} 
//	}
	InitRegionShow();
} 
var ajax_reportconfirm_callback= {
	onSuccess: function(eiInfo) {
		var grid = efgrid.getGridObject("ef_grid_feedbackreport");
		grid.refresh(eiInfo);//刷新
//		efform_onload();
		
	},
	onFail:function(eMsg)
	{
		alert("确认失败，原因："+eMsg); 
	}
}

button_reportcancel_onclick = function ()//FEEDBACK 返回
{
	InitRegionShow();
} 


button_delete1_onclick = function (){
	var grid=isSelected("ef_grid_feedbackreport");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_feedbackreport", "ZM","ZMCK11","delete",true);
	}); 
}

efgrid_afterAddNewRow = function(grid_id){ 
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows(); 
	if(grid_id=="ef_grid_feedbackreport")
	{		
		var fdDepartment=$('#fdCreateDepartment').val();		
		var fdDepartmentId=$('#fdCreateDepartmentId').val();	  
	   
		for(var i = 0 ; i < rows.length;i++){		
//			grid.setCellValue(rows[i],5,fdCreateDepartment,TYPE_DATA); 
//			grid.setCellValue(rows[i],1,fdDepartmentId,TYPE_DATA); 
			grid.setCellValue(rows[i],1,fdDepartment,TYPE_DATA); 
			
//			grid.setCellValue(rows[i],6,fdCreateDepartment,TYPE_DATA); 
		}
	}
}

/**
 * 操作完成后清空该region内的各数据项的值
 */
var clearAfterSolve=function(region) { 
	var temp;
	//遍历INPUT
	$('#'+region).find("input").each(function (){
		temp = $(this).attr("id");
		$('#'+temp).val("");
//		$(this).removeData();
	});
	//遍历SELECT
	$('#'+region).find("select").each(function (){
		temp = $(this).attr("id");
		$('#'+temp).val("");
	});
	//遍历TEXTAREA
	$('#'+region).find("textarea").each(function (){
		temp = $(this).attr("id");
		$('#'+temp).val("");
	});
};
